﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Interop;
using System.Windows;
using System.Drawing;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Ink;
using static SuporeSliplampApp.Util.PicOparator;

namespace SuporeSliplampApp.Util
{
    public class PicOparator
    {
        //private string _image = null;
        //Mat src, img1, mask, final;
        //OpenCvSharp.Point point;
        //List<OpenCvSharp.Point> pts;

        //public  void SetMouseCallback(string windowName, CvMouseCallback onMouse, IntPtr userData = default(IntPtr));
        // public delegate void MouseCallback(MouseEvent @event, int x, int y, MouseEvent flags, IntPtr userdata);





        //public PicOparator(string url)
        //{
        //    CvMouseCallback draw = new CvMouseCallback(draw_circle);
        //    //Image image = new Image(url);
        //    src = Cv2.ImRead(url,ImreadModes.Grayscale);
        //    img1 = new Mat(src.Size(),src.Type());
        //    //Cv2.NamedWindow("src1",WindowMode.AutoSize);
        //    // Cv2.SetMouseCallback("Source", mouseHandler);
        //    Cv2.ImShow("src1", src);
        //   img1 =src.Clone();
        //    System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(src);
        //    IntPtr ptr = System.Runtime.InteropServices.GCHandle.ToIntPtr(handle);
        //    Cv2.SetMouseCallback("SRC", draw, ptr);

        //    Cv2.WaitKey(0);

        //}
        //OpenCvSharp.Point sp = new OpenCvSharp.Point(-1, -1);
        //OpenCvSharp.Point ep = new OpenCvSharp.Point(-1, -1);
        //public delegate void CvMouseCallback(MouseEvent @event, int x, int y, MouseEvent flags, IntPtr userdata);

        //private void SetSource(string url)
        //{
        //    using (var src = new Mat(url, ImreadModes.Unchanged))
        //    {
        //        var bmp = src.ToBitmap();
        //        var returnSource = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

        //    }
        //}
        //public void SetMouseCallback(string windowName, CvMouseCallback draw, IntPtr userData = default(IntPtr)) { }


        //public static void readgImg(string path)
        //{
        //    Mat img;
        //    Mat[] vc;
        //    img = Cv2.ImRead(path,ImreadModes.Grayscale);
        //    Cv2.ImShow("img",img);
        //    vc =Cv2.Split(img);
        //    Console.WriteLine(vc);
        //    Cv2.WaitKey(0);
        //    Cv2.DestroyAllWindows();


        //    //Cv2.ImWrite(path+"_1",img);
        //    //var vd = Cv2.VideoCapture("test.mp4");
        //    //Cv2.Circle();

        //}
        //public void draw_circle(MouseEvent @event,int x, int y, MouseEvent flags, IntPtr userdata)
        //{
        //    //img1 = src.Clone();
        //    System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.FromIntPtr(userdata);
        //    Mat src = (Mat)handle.Target;
        //    Scalar scalar = new Scalar(0,0,255);
        //    if (@event == MouseEvent.LButtonDown)
        //    {
        //        Cv2.Circle(src,new OpenCvSharp.Point(x,y),100,scalar,3,LineTypes.AntiAlias,0);
        //        Cv2.ImShow("src", src);
        //    }    
        //}
        //void mouseHandler(int events, int x, int y, int n, IntPtr intPtr)
        //{
        //int var = 0;

        //Scalar scarlar = new Scalar(0,0,255);

        //if (System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
        //{
        //    img1 = src.Clone();
        //    point = new OpenCvSharp.Point(x,y);
        //    Cv2.Circle(img1,Mouse.GetPosition().X,y,2, scarlar, -1,LineTypes.Link8,0);
        //    pts.Add(point);
        //    var++;
        //    if (var > 1)
        //        Cv2.Line(img1, pts[var-2].X, pts[var - 2].Y, pts[var - 1].X, pts[var - 1].Y,scarlar,2,LineTypes.Link8,0);
        //    Cv2.ImShow("Source", img1);
        //}
        //}

        // private Mat ColorTemperature(Mat input, byte n)

        //        Mat result = input.Clone();
        //        Mat img = new Mat();
        //        int row = input.Rows;
        //        int col = input.Cols;
        //        //b/*yte level = (byte)n / 2;*/
        //        //for (var y = 0; y < input.Height; y++)
        //        //{
        //        //    for (var x = 0; x < input.Width; x++)
        //        //    {
        //        //        Vec3b color = input.Get<Vec3b>(y,x);
        //        //        var B = color.Item0;
        //        //        var G = color.Item1;
        //        //        var R = color.Item2;
        //        //        R = (byte)R + level;

        //        //    }
        //        //}
        //        img = Cv2.ImRead("1.jpg",ImreadModes.Grayscale);
        //        Cv2.ImShow("", img);
        //        for (int i = 0; i < row; ++i)
        //        {
        //            IntPtr a = input.Ptr(i);
        //            IntPtr b = result.Ptr(i);
        //            for (int j = 0; j < col; ++j)
        //            {
        //                int R, G, B;
        //                R = a.ToInt32();

        //            }
        //        }
        //            return result;
    }
}
    

